package com.renjun.smweb.controller.TestController;

import com.alibaba.fastjson.JSONObject;
import com.renjun.smweb.annotation.AuthorityDeclaration;
import com.renjun.smweb.commons.util.ResponseUtils;
import com.renjun.smweb.service.TestService.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.Map;

/**
 * Created by huamin on 2017/2/13.
 */
@Controller
@RequestMapping("/test")
public class TestController {
    @Autowired
    private TestService testService;

    @RequestMapping(value = "/testQuery", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "testQuery", desc = "testQuery 测试查询记录")
    public JSONObject testQuery(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject list = null;
        try {
            list = testService.testQuery(map);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @RequestMapping(value = "/testAdd", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "testAdd", desc = "testAdd 测试新增记录")
    public JSONObject testAdd(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject list = null;
        try {
            list = testService.testAdd(map);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @RequestMapping(value = "/testUpdate", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "testUpdate", desc = "testUpdate 测试更新记录")
    public JSONObject testUpdate(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject list = null;
        try {
            list = testService.testUpdate(map);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @RequestMapping(value = "/testDelete", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "testDelete", desc = "testDelete 测试删除记录")
    public JSONObject testDelete(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject list = null;
        try {
            list = testService.testDelete(map);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
